package src;

import javax.swing.*;
import java.awt.*;

public class CardDeleteDialog extends JDialog {
    private JTextField cardNumberField;
    private boolean confirmed = false;

    public CardDeleteDialog(Frame owner) {
        super(owner, "删除银行卡", true);
        setSize(300, 150);
        setLocationRelativeTo(owner);

        JPanel panel = new JPanel(new GridLayout(3, 2, 10, 10));
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

        // 添加输入字段
        panel.add(new JLabel("卡号:"));
        cardNumberField = new JTextField();
        panel.add(cardNumberField);

        // 添加按钮
        JButton confirmButton = new JButton("确认删除");
        JButton cancelButton = new JButton("取消");

        JPanel buttonPanel = new JPanel();
        buttonPanel.add(confirmButton);
        buttonPanel.add(cancelButton);
        panel.add(buttonPanel);

        // 添加事件监听器
        confirmButton.addActionListener(e -> {
            if (validateInput()) {
                int result = JOptionPane.showConfirmDialog(
                    this,
                    "确定要删除该银行卡吗？此操作不可恢复！",
                    "确认删除",
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.WARNING_MESSAGE
                );
                
                if (result == JOptionPane.YES_OPTION) {
                    confirmed = true;
                    dispose();
                }
            }
        });

        cancelButton.addActionListener(e -> dispose());

        add(panel);
    }

    private boolean validateInput() {
        if (cardNumberField.getText().trim().isEmpty()) {
            JOptionPane.showMessageDialog(this, "请输入卡号！", "错误", JOptionPane.ERROR_MESSAGE);
            return false;
        }
        return true;
    }

    public boolean isConfirmed() {
        return confirmed;
    }

    public String getCardNumber() {
        return cardNumberField.getText().trim();
    }
} 